﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AffinityORMLibrary.DataTypes;

namespace AffinityORMLibrary.DataLayer.Assembler
{
    class SysTableInfoAssembler : IAssembler<SysTableInfo>
    {
        public SysTableInfo Construct(System.Data.IDataReader reader)
        {
            SysTableInfo result = new SysTableInfo();

            int tableCatalogIndex = reader.GetOrdinal("TABLE_CATALOG");
            if (!reader.IsDBNull(tableCatalogIndex))
            {
                result.TABLE_CATALOG = reader.GetString(tableCatalogIndex);
                result.UpdateOldKey("TABLE_CATALOG", result.TABLE_CATALOG);
            }

            int tableSchemaIndex = reader.GetOrdinal("TABLE_SCHEMA");
            if (!reader.IsDBNull(tableSchemaIndex))
            {
                result.TABLE_SCHEMA = reader.GetString(tableSchemaIndex);
                result.UpdateOldKey("TABLE_SCHEMA", result.TABLE_SCHEMA);
            }

            int tableNameIndex = reader.GetOrdinal("TABLE_NAME");
            if (!reader.IsDBNull(tableNameIndex))
            {
                result.TABLE_NAME = reader.GetString(tableNameIndex);
                result.UpdateOldKey("TABLE_NAME", result.TABLE_NAME);
            }

            int tableTypeIndex = reader.GetOrdinal("TABLE_TYPE");
            if (!reader.IsDBNull(tableTypeIndex))
            {
                result.TABLE_TYPE = reader.GetString(tableTypeIndex);
                result.UpdateOldKey("TABLE_TYPE", result.TABLE_TYPE);
            }

            return result;
        }
    }
}
